// pages/team/team.js
const app = getApp()
var api = require("../../utils/api.js")
var util = require("../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 组件所需的参数
    nvabarData: {
      showCapsule: 1, //是否显示左上角图标   1表示显示    0表示不显示
      title: '团队', //导航栏 中间的标题
      hidden: 0
    },
    height: app.globalData.height * 2 + 20, // 此页面 页面内容距最顶部的距离
    teamId: 0,
    pages: 1,
    content: {},
    list: [],
    partnerList: [],
    textLen: 500,
    isOpen: false,
    isShowMore: true,
  },
  onSelectPartner(e) {
    let id = e.currentTarget.dataset.item.id
    wx.navigateTo({
      url: '../partner/partner?id=' + id
    })
  },
  onSelectLocation(e) {
    let id = e.currentTarget.dataset.item.locationId
    wx.navigateTo({
      url: '../country/index?id=' + id
    })
  },
  onOpen() {
    var that = this;
    that.setData({
      isOpen: !that.data.isOpen
    });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options)
    that.setData({
      teamId: options.id || 1
    });
    var data = {
      teamId: options.id || 1,
    };
    var url = app.u.url + app.u.team.GetTeam;
    api.requestUrl(data, url).then(res => {
      console.log(res.data)
      let strLength = util.getTrueLength(res.data.info.details)
      if (strLength > that.data.textLen) {
        that.setData({
          isShowMore: false
        });
      } else {
        that.setData({
          isShowMore: true
        });
      }
      that.setData({
        content: res.data.info
      });
    });
    this.onSelect();
    this.onSelectSponsor();
  },
  onSelect() {
    var that = this
    var data = {
      teamId: that.data.teamId,
      currentPage: that.data.pages
    }
    var url = app.u.url + app.u.team.NextLocation
    api.requestUrl(data, url).then(res => {
      console.log(res.data)
      that.setData({
        list: res.data
      });
    })
  },
  onSelectSponsor() {
    var that = this
    var data = {
      teamId: that.data.teamId,
      currentPage: that.data.pages
    }
    var url = app.u.url + app.u.team.NextSponsor
    api.requestUrl(data, url).then(res => {
      console.log(res.data)
      that.setData({
        partnerList: res.data
      });
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})